package com.hhs.FileUpload.controller;




import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.json.JSONUtil;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhs.FileUpload.entity.FileInfo;
import com.hhs.FileUpload.entity.FileInfoDTO;
import com.hhs.FileUpload.entity.FileVerify;
import com.hhs.FileUpload.service.FileService;
import com.hhs.FileUpload.util.JsonResult;



import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;

/**
 * explain : 此控制层需要实现所有可以预想的到文件操作类型
 * <p>
// * 工具类: hutool,common-io,common-upload
 * <p>
 * 功能-001: 前端axios,后端post请求上传单个文件
 * 功能-002: 前端axios,后端post请求上传多个文件
 */
@Slf4j
@RestController
@RequestMapping("/test-file")
@CrossOrigin

public class MinioController {

    @Autowired
    private FileService fileService;

    /**
     * 校验文件
     */

    @PostMapping("/verifyFile")
    public JsonResult<FileVerify> verifyFile(FileVerify fileVerify) {
        try {
            fileVerify = fileService.verifyFile(fileVerify);
        } catch (Exception e) {
            log.error("上传文件失败....", e);
            return JsonResult.error();
        }
        return JsonResult.success(fileVerify);
    }

    /**
     * 断点上传文件
     * <p>
     * 参考:
     *
     * @return JsonResult
     */

    @PostMapping("/breakpointUpload")
    public JsonResult<FileVerify> breakpointUpload(FileVerify fileVerify) {
        try {

            synchronized (FileVerify.class) {
                log.warn("breakpointUpload-传参->{}", JSONUtil.toJsonStr(fileVerify));
                fileVerify = fileService.breakpointUpload(fileVerify);
            }

        } catch (Exception e) {
            log.error("上传文件失败....", e);
            return JsonResult.error();
        }
        return JsonResult.success(fileVerify);
    }



}
